<?php
/**
 * Created by PhpStorm.
 * User: xlosy
 * Date: 2018/3/24
 * Time: 21:36
 */

namespace app\index\model;


use think\Model;

class Film extends Model
{

    // 设置返回数据集的对象名
    protected $resultSetType = 'collection';

    //自定义初始化
    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }

    public function get_recommend_list($catalog_id)
    {
        $film = new Film();
        // 查询数据集
        $data = $film->where(['isUse'=>'1','catalog_id'=>"$catalog_id"])
        ->order('updateTime','desc')
        ->limit(12)
        ->select();
        return $data;
    }


    public function get_evaluation_list($catalog_id)
    {
        $film = new Film();
        // 查询数据集
        $data = $film->where(['isUse'=>'1','catalog_id'=>"$catalog_id"])
        ->order('evaluation','desc')
        ->limit(16)
        ->select();
        return $data;
    }

    public function get_film_list($pageSize){
        $film = new Film();
        // 查询数据集
        if(!is_null(input('name')) && input('name') !=''){
            $film->where('name','like','%'.input('name').'%');
        }
        if(!is_null(input('actor')) && input('actor') !=''){
            $film->where('actor','like','%'.input('actor').'%');
        }
        $condion = array();
        $condion['isUse'] = '1';
        if(!is_null(input('cataLog_id'))){
            $condion['cataLog_id'] = input('cataLog_id');
        }
        $uid = session('uid');
        $adminUId = session('AdminUId');
        if($adminUId==null){
            if($uid == null){
                $condion['isVip'] = "0";
            }else{
                $condion['isVip'] = "1";
            }
        }


        $data = $film->where($condion)->paginate($pageSize);
        return $data;
    }

    public function get_film_by_id($id){
        $film = new Film();
        $return = $film->get($id);
        return $return;
    }

    public function get_film_by_type_id($id){
        return Film::where('type_id',$id)->limit(0,8)->select();
    }

    public function resouces(){
        return $this->hasMany('Res','film_id','id');
    }

}